﻿using System;

namespace Index.TokenMap
{
    public class SegmentName
    {
        public static readonly char[] Separators = {'-'};

        public uint Generation { get; set; }
        public uint MaxTokenId { get; set; }

        public SegmentName()
        {
            
        }

        public SegmentName(string fileName)
        {
            string[] parts = fileName.Split(Separators);

            if(parts.Length != 2)
            {
                throw new ArgumentException("Invalid file name format: " + fileName + ". Must be: 0000000000-0000000000");
            }

            this.Generation = Convert.ToUInt32(parts[0], 10);
            this.MaxTokenId = Convert.ToUInt32(parts[1], 10);
        }

        public override string ToString()
        {
            return string.Format("{0:0000000000}-{1:0000000000}", this.Generation, this.MaxTokenId);
        }
    }
}